package com.touch.jgloo.owt;

import com.touch.jgloo.core.JGLTextObject;
/** 
 * A JGLLabel is a JGLComponent that only displays text.
 * @author Homicidal Monkey
 * @version 10.1.9
 * @since r419
 * @see com/touch/Licence
 */
public final class JGLLabel extends JGLComponent
{
	//Caption object
	private JGLTextObject caption;
	/**
	 * Constructs a new JGLLabel object
	 * @param caption Caption to be displayed
	 * @since r461
	 */
	public JGLLabel(final String caption)
	{		
		//set the text
		this.setText(caption);
	}
	/**
	 * Sets the text of the JGLLabel
	 * @param caption Caption of the label
	 * @since r461
	 */
	public final  void setText(final String caption)
	{
		//create a new JGLTextObject
		this.caption = JGLTextObject.createTextObject(caption, JGLComponent.TEXT_TYPE);
		//apply the style sheet
		this.applyStyleSheet(JGLStyleSheet.DEFAULT_PANEL);
		//set the label's size
		this.setSize(caption.length() * 10, 10);
	}
	/**
	 * Returns the text of the JGLLabel
	 * @return Caption of the JGLLabel as a String
	 * @since r461
	 */
	public final  String getText()
	{
		//return the caption
		return this.caption.getCaption();
	}
	/**
	 * Returns the JGLTextObject of the caption
	 * @return Caption as a JGLTextObject
	 * @since r461
	 */
	public final  JGLTextObject getTextObject()
	{
		//return the caption
		return this.caption;
	}
	/**
	 * Returns the length of the caption
	 * @return Size of the caption
	 */
	public final  int length()
	{
		//return the caption's size
		return this.caption.length();
	}
	@Override
	public final  void applyStyleSheet(final JGLStyleSheet ss) 
	{	
		//caption.setTexture(ss.componentBackgroundTexture);		
		caption.setColor(ss.componentBackgroundColor);
	}
	public final  void repositioned(final int x, final int y, final int z) {}
	
	public final  void resized(final int w, final int h) {}		
	
	public final  void render() 
	{	
		//determine if the JGLLabel is visible
		if(this.isVisible() == false)
			//if not, return
			return;
		//push the matrix up one
		GL_INSTANCE.glPushMatrix();
			//translate to the JGLLabel's position
			GL_INSTANCE.glTranslatef(this.getPosition().x, this.getPosition().y, this.getPosition().z);
			//render the caption
			caption.render();
		//push the matrix down one
		GL_INSTANCE.glPopMatrix();
	}
	public final  void clean() {}
	public final  void compile() {}	
	public JGLLabel clone()
	{
		final JGLLabel clone = new JGLLabel(this.caption.getCaption());
		
		clone.setPosition(this.getPositionX(), this.getPositionY(), this.getPositionZ());
		clone.setParentPosition(this.getParentPosition().x, this.getParentPosition().y, this.getParentPosition().z);
		clone.setVisible(this.isVisible());		
		
		return clone;
	}
}
